package sub

import (
	"fmt"
	"quipus/cmd/qpc/sub"
	"quipus/internal/utils"
	v1pb "quipus/proto/gen/api/v1"

	"github.com/spf13/cobra"
)

var (
	name     string
	model    string
	url      string
	spId     int32
	authinfo []string
)

func init() {
	createCmd.PersistentFlags().StringVarP(&name, "name", "n", "", "unique name for llm model entity")
	createCmd.PersistentFlags().StringVarP(&model, "model", "m", "", "the model flag for the service")
	createCmd.PersistentFlags().Int32VarP(&spId, "prvider", "p", 0, "service provider id")

	modelCmd.AddCommand(createCmd)
}

var createCmd = &cobra.Command{
	Use:   "create",
	Short: "Run the cmd to create llm model",
	RunE: func(cmd *cobra.Command, args []string) error {
		qconn, e := sub.NewGrpcConnect(sub.QpConfig.QPAddress)
		if e != nil {
			return e
		}

		qclient := v1pb.NewLLMServiceClient(qconn)
		ctxWithToken := sub.NewCtxWithToken(sub.QpConfig.Token)
		provider := utils.BuildUrn(utils.ProviderUrnPrefix, spId)
		in := &v1pb.CreateLLMModelRequest{Name: name, Model: model, Sp: provider}

		rsp, err := qclient.CreateLLMModel(ctxWithToken, in)
		if err != nil {
			return err
		}
		fmt.Print(rsp)
		return nil
	},
}
